package com.yanmaohu.yulia.bean;

/**
 * @author Bright Lee
 */
public final class LocalOrSchemaQualifiedName implements TableOrQueryName {

    private final int beginIndex;
    private final SchemaName schemaName;
    private final boolean module;
    private final Identifier qualifiedIdentifier;

    public LocalOrSchemaQualifiedName(SchemaName schemaName, Identifier qualifiedIdentifier) {
        if (schemaName != null) {
            this.beginIndex = schemaName.getBeginIndex();
        } else {
            this.beginIndex = qualifiedIdentifier.getBeginIndex();
        }
        this.schemaName = schemaName;
        this.module = false;
        this.qualifiedIdentifier = qualifiedIdentifier;
    }

    public LocalOrSchemaQualifiedName(int beginIndex, Identifier qualifiedIdentifier) {
        this.beginIndex = beginIndex;
        this.schemaName = null;
        this.module = true;
        this.qualifiedIdentifier = qualifiedIdentifier;
    }

    public int getBeginIndex() {
        return beginIndex;
    }

    public int getEndIndex() {
        return qualifiedIdentifier.getEndIndex();
    }

    public SchemaName getSchemaName() {
        return schemaName;
    }

    public boolean isModule() {
        return module;
    }

    public Identifier getQualifiedIdentifier() {
        return qualifiedIdentifier;
    }

}
